package name.wilbur.course.db.bigone.ui;

import name.wilbur.course.db.bigone.control.PersonalInfoMgr;
import name.wilbur.course.db.bigone.model.City;
import name.wilbur.course.db.bigone.model.Profile;
import name.wilbur.course.db.bigone.model.User;

import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;

public class PersonalInfoWin extends BaseWindow {
//	private Shell sShell = null;  //  @jve:decl-index=0:visual-constraint="10,10"
	private PersonalInfoMgr mgr;
	private User me = null;
	private Label nameL = null;
	private Label genderL = null;
	private Label phoneL = null;
	private Text phoneT = null;
	private Combo genderC = null;
	private Combo cityC = null;
	private Button resetB = null;
	private Button submitB = null;
	
	public PersonalInfoWin(User me) {
		super();
		this.me = me;
		mgr = new PersonalInfoMgr(me);
	}
	public PersonalInfoWin(Display disp, User me) {
		super(disp);
		this.me = me;
		mgr = new PersonalInfoMgr(me);
	}
	/**
	 * This method initializes sShell
	 */
	public void createSShell() {
		final GridData oneSpanGridData = new GridData(GridData.FILL, GridData.FILL, true, false, 1, 1);
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 3;
		sShell = new Shell();
		sShell.setText("Shell");
		sShell.setLayout(gridLayout);
		sShell.setSize(new Point(290, 172));
		genderL = new Label(sShell, SWT.NONE);
		genderL.setText("性别");
		genderC = new Combo(sShell, SWT.NONE);
		genderC.setLayoutData(oneSpanGridData);
		genderC.add("男", 0);
		genderC.add("女", 1);
		genderC.select(0);
		Label filler1 = new Label(sShell, SWT.NONE);
		filler1.setLayoutData(oneSpanGridData);
		nameL = new Label(sShell, SWT.NONE);
		nameL.setText("城市");
		cityC = new Combo(sShell, SWT.NONE);
		cityC.setLayoutData(oneSpanGridData);
		Label filler2 = new Label(sShell, SWT.NONE);
		filler2.setLayoutData(oneSpanGridData);
		phoneL = new Label(sShell, SWT.NONE);
		phoneL.setText("电话");
		phoneT = new Text(sShell, SWT.BORDER);
		phoneT.setLayoutData(oneSpanGridData);
		Label filler3 = new Label(sShell, SWT.NONE);
		filler3.setLayoutData(oneSpanGridData);
		resetB = new Button(sShell, SWT.NONE);
		resetB.setText("重置");
		resetB.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				genderC.select(0);
				cityC.select(-1);
				phoneT.setText("");
			}
		});
		submitB = new Button(sShell, SWT.NONE);
		submitB.setText("确认");
		submitB.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				mgr.updatePersonalInfo(genderC.getText(), cityC.getText(), phoneT.getText());
				close();
			}
		});
	}

	public void initWindowData() {
		cityC.setItems(mgr.getAllCityNames());
		Profile p = mgr.getProfile();
		if (p != null) {
			cityC.setText(mgr.getCity().getCityName());
			genderC.setText(p.getGender());
			phoneT.setText(p.getPhoneNumber());
		}
	}
}
